package com.czy.owner.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.FindStrategyModel;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 * Created by wangyang on 2017/5/14 0014.
 */

public class FindStrategyAdapter extends RecyclerArrayAdapter<FindStrategyModel> {
    private Context context;

    public FindStrategyAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new FindStrategyViewHolder(parent, context);
    }

    class FindStrategyViewHolder extends BaseViewHolder<FindStrategyModel> {
        private ImageView imgItemFindStrategeBg;
        private TextView tvItemFindStrategeName;

        public FindStrategyViewHolder(ViewGroup parent, Context ctx) {
            super(parent, R.layout.item_find_stratege);
            imgItemFindStrategeBg = $(R.id.img_item_find_stratege_bg);
            tvItemFindStrategeName = $(R.id.tv_item_find_stratege_name);
        }

        private String[] colorStr = {"#626AEA","#389EFD","#F66508","#78AE2D"};

        @Override
        public void setData(FindStrategyModel data) {
            super.setData(data);
            tvItemFindStrategeName.setText(data.getInfoBaseName());
            int colorIndex = getAdapterPosition() % 4;
            GradientDrawable p = (GradientDrawable) tvItemFindStrategeName.getBackground();
            p.setColor(Color.parseColor(colorStr[colorIndex]));
            GlideUtils.loadImage(context, data.getUrl(), imgItemFindStrategeBg, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.default_banner, R.mipmap.default_banner);
        }
    }

}
